#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10010;
int n,m,ans,a[maxn];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    cin >> n;
	m = n;
    for (int i = 1; i <=n; i++)
    {
    	cin >> a[i];
	}
    make_heap(a+1, a+n+1, cmp);
    for (int i = 1; i < n; i++)
    {
        int x = a[1];
		pop_heap(a+1, a+m+1, cmp);
        int y = a[1];
		pop_heap(a+1, a+m, cmp);
        ans += x+y;
		a[m-1] = x+y;
		push_heap(a+1, a+m, cmp);
        m--;
    }
    cout << ans << endl;
    return 0;
}
